package com.example.tm_androidbasics;

import java.util.Date;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.tm_androidbasics.basics.Basics;
import com.example.tm_androidbasics.tasks.UITask;

public class MainActivity extends Activity {
	private int countDown = 10;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Basics basics = new Basics();
		basics.doSomething();

		((ProgressBar)findViewById(R.id.progressBar)).setMax(100);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.action_startTask:
			(new UITask(this)).execute(countDown);
			break;
		}
		return true;
	}

	public void UpdateProgress(Double value) {
		TextView progressValue = (TextView)findViewById(R.id.progressValue);
		ProgressBar  progressBar = (ProgressBar)findViewById(R.id.progressBar);
		
		progressValue.setText(value.toString());
		progressBar.setProgress(value.intValue());
	}

	public void UpdateResult(Date result) {
		((TextView)findViewById(R.id.taskResult)).setText(String.format("%tT", result));
	}
}
